import 'package:flutter/material.dart';

class ThrottleUtil {
  static const Duration _delay = Duration(milliseconds: 800);
  var enable = true;

  ///防止重复点击
  ///func 要执行的方法
  VoidCallback throttle(
    VoidCallback func, {
    Duration delay = _delay,
  }) {
    return () {
      if (enable) {
        func();
        enable = false;
        Future.delayed(delay, () {
          enable = true;
        });
      }
    };
  }
}
